package Demo_work;


import java.util.Scanner;
class TreeNode1 {
    char val;
    TreeNode1 left;
    TreeNode1 right;
    public TreeNode1(char val) {
        this.val = val;
    }
}
public class test1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (scan.hasNextLine()) { // 注意 while 处理多个 case
            String str = scan.nextLine();
            TreeNode1 root = CreateTree(str);
            inorder(root);
        }
    }
    //根据字符建一个二叉树
    public static int i = 0;
    public static TreeNode1 CreateTree(String s) {
        TreeNode1 root = null;
        char ch = s.charAt(i);
        if(ch != '#') {
            root = new TreeNode1(ch);
            i++;
            root.left = CreateTree(s);
            root.right = CreateTree(s);
        } else {
            i++;
        }
        return root;
    }

    //写一个中序遍历
    public static void inorder(TreeNode1 root) {
        if(root == null) {
            return;
        }
        inorder(root.left);
        System.out.print(root.val+" ");
        inorder(root.right);
    }


}
